CALIFORNIA PENAL CODE § 1002-1008
A demurrer is an alternative to pleading guilty, not guilty or no contest to a criminal charge. The distinction is that when you plead you make a tacit legal concession that there was a crime committed so, by pleading “not guilty” you are accepting that there was a crime but are contesting the facts (mainly that you committed the crime). A demurrer does the opposite; you admit that the facts are correct but argue that no crime was committed. In the case of marijuana in California, for example, you would argue that the defendant did grow or possess marijuana (cannabis) since the defendant has a medical marijuana approval, their cultivation or use was lawful and not a crime.
If you plead “not guilty” you have removed your ability to argue for the demurrer, even though your legal argument (medical marijuana defense) is still the same. But you can only demur at the arraignment. After that it is too late.
CALIFORNIA PENAL CODE SECTION 1002-1008
1002. The only pleading on the part of the defendant is either a demurrer or a plea.
1003. Both the demurrer and plea must be put in, in open Court, either at the time of the arraignment or at such other time as may be allowed to the defendant for that purpose.
1004. The defendant may demur to the accusatory pleading at any time prior to the entry of a plea, when it appears upon the face thereof either:
1. If an indictment, that the grand jury by which it was found had no legal authority to inquire into the offense charged, or, if any information or complaint that the court has no jurisdiction of the offense charged therein;
3. That more than one offense is charged, except as provided in Section 954;
4. That the facts stated do not constitute a public offense;
5. That it contains matter which, if true, would constitute a legal justification or excuse of the offense charged, or other legal bar to the prosecution.
1005. The demurrer must be in writing, signed either by the defendant or his counsel, and filed. It must distinctly specify the grounds of objection to the accusatory pleading or it must be disregarded.
1006. Upon the demurrer being filed, the argument upon the objections presented thereby must be heard immediately, unless for exceptional cause shown, the court shall grant a continuance. Such continuance shall be for no longer time than the ends of justice require, and the court shall enter in its minutes the facts requiring it.
1007. Upon considering the demurrer, the court must make an order either overruling or sustaining it. If the demurrer to an indictment or information is overruled, the court must permit the defendant, at the defendant’s election, to plead, which the defendant must do forthwith, unless the court extends the time. If the demurrer is sustained, the court must, if the defect can be remedied by amendment, permit the indictment or information to be amended, either forthwith or within such time, not exceeding 10 days, as it may fix, or, if the defect or insufficiency therein cannot be remedied by amendment, the court may direct the filing of a new information or the submission of the case to the same or another grand jury. If the demurrer to a complaint is sustained, the court must, if the defect can be remedied, permit the filing of an amended complaint within such time not exceeding 10 days as it may fix. The orders made under this section shall be entered in the docket or minutes of the court.
1008. If the demurrer is sustained, and no amendment of the accusatory pleading is permitted, or, in case an amendment is permitted, no amendment is made or amended pleading is filed within the time fixed therefor, the action shall be dismissed, and, except as provided in Section 1010, the court must order, if the defendant is in custody, that he be discharged or if he has been admitted to bail, that his bail be exonerated, or, if money or other property has been deposited instead of bail for his appearance, that such money or other property be refunded to him or to the person or persons found by the court to have deposited such money or other property on his behalf.
950. The accusatory pleading must contain:
952. In charging an offense, each count shall contain, and shall be sufficient if it contains in substance, a statement that the accused has committed some public offense therein specified. Such statement may be made in ordinary and concise language without any technical averments or any allegations of matter not essential to be proved. It may be in the words of the enactment describing the offense or declaring the matter to be a public offense, or in any words sufficient to give the accused notice of the offense of which he is accused. In charging theft it shall be sufficient to allege that the defendant unlawfully took the labor or property of another.
954. An accusatory pleading may charge two or more different offenses connected together in their commission, or different statements of the same offense or two or more different offenses of the same class of crimes or offenses, under separate counts, and if two or more accusatory pleadings are filed in such cases in the same court, the court may order them to be consolidated. The prosecution is not required to elect between the different offenses or counts set forth in the accusatory pleading, but the defendant may be convicted of any number of the offenses charged, and each offense of which the defendant is convicted must be stated in the verdict or the finding of the court; provided, that the court in which a case is triable, in the interests of justice and for good cause shown, may in its discretion order that the different offenses or counts set forth in the accusatory pleading be tried separately or divided into two or more groups and each of said groups tried separately. An acquittal of one or more counts shall not be deemed an acquittal of any other count.