within the state; when and by what courts order may be
issued.
The following courts and judges may, under the indicated circumstances, order production as witnesses of persons confined by court order in institutions within the state.
1. If the criminal action or proceeding is one pending in a superior court or with a superior court judge sitting as a local criminal court, such court may, except as provided in subdivision four, order the production as a witness therein of a person confined in any institution in the state.
2. If the criminal action or proceeding is one pending in a district court or the New York City criminal court, such court may order the production as a witness therein of a person confined in any institution within the state other than a state prison. Production therein of a prospective witness confined in a state prison may, except as provided in subdivision four, be ordered, upon application of the party desiring to call him, by a judge of a superior court holding a term thereof in the county in which the action or proceeding is pending.
3. If the criminal action or proceeding is one pending in a city court or a town court or a village court, such court may order the production as a witness therein of a person confined in a county jail of such county. Production therein of a prospective witness confined in any other institution within the state may, except as provided in subdivision four, be ordered, upon application of the party desiring to call him, by a judge of a superior court holding a term thereof in the county in which the action or proceeding is pending.
4. Regardless of the court in which the criminal action or proceeding is pending, production as a witness therein of a prisoner who has been sentenced to death may be ordered, upon application of the party desiring to call him, only by a justice of the appellate division of the department in which the action or proceeding is pending. The application for such order, if made by the defendant, must be upon notice to the district attorney of the county in which the action or proceeding is pending, and an application made by either party must be based upon a showing that the prisoner's attendance is clearly necessary in the interests of justice. Upon issuing such an order, the appellate division justice may fix and include therein any terms or conditions which he deems appropriate for execution thereof.